strlcpy_strlcat_warning_removed
authorLLVM Packaging Team <pkg-llvm-team@lists.alioth.debian.org>
Tue, 16 Dec 2025 11:47:30 +0000 (12:47 +0100)
committerSylvestre Ledru <sylvestre@debian.org>
Tue, 16 Dec 2025 11:47:30 +0000 (12:47 +0100)
Gbp-Pq: Name 23-strlcpy_strlcat_warning_removed.diff

clang/include/clang/Basic/Builtins.td
clang/lib/AST/Decl.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
clang/test/Sema/builtins.c
clang/test/Sema/warn-strlcpycat-size.c [deleted file]

index 5ebb82180521d127ace11320892d912721727c20..452b677c9df0682bd3b15d8a7a9add4807f652bc 100644 (file)
@@ -3471,7 +3471,8 @@ def SigLongJmp : GNULibBuiltin<"setjmp.h"> {
 
 // non-standard but very common
 
-def StrlCpy : GNULibBuiltin<"string.h"> {
+/*
+  def StrlCpy : GNULibBuiltin<"string.h"> {
   let Spellings = ["strlcpy"];
   let Prototype = "size_t(char*, char const*, size_t)";
 }
@@ -3480,6 +3481,7 @@ def StrlCat : GNULibBuiltin<"string.h"> {
   let Spellings = ["strlcat"];
   let Prototype = "size_t(char*, char const*, size_t)";
 }
+*/
 
 def ObjcMsgSend : ObjCLibBuiltin<"objc_message.h"> {
   let Spellings = ["objc_msgSend"];
index bd1b5950d30a6c4f1b672f1d8acc2243711ad7e1..982e6c5cf9f20182eb4b682e4910f53df36707e8 100644 (file)
@@ -4512,13 +4512,13 @@ unsigned FunctionDecl::getMemoryFunctionKind() const {
   case Builtin::BImemmove:
     return Builtin::BImemmove;
 
-  case Builtin::BIstrlcpy:
-  case Builtin::BI__builtin___strlcpy_chk:
-    return Builtin::BIstrlcpy;
+//  case Builtin::BIstrlcpy:
+//  case Builtin::BI__builtin___strlcpy_chk:
+//    return Builtin::BIstrlcpy;
 
-  case Builtin::BIstrlcat:
-  case Builtin::BI__builtin___strlcat_chk:
-    return Builtin::BIstrlcat;
+//  case Builtin::BIstrlcat:
+//  case Builtin::BI__builtin___strlcat_chk:
+//    return Builtin::BIstrlcat;
 
   case Builtin::BI__builtin_memcmp:
   case Builtin::BImemcmp:
index 41bcf8fd493fcf62d13e1e4465ed9b899e778f88..3eef68d5d9827776e9a13751a106910f5e0e71d6 100644 (file)
@@ -1354,8 +1354,8 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
   case Builtin::BI__builtin___memcpy_chk:
   case Builtin::BI__builtin___memmove_chk:
   case Builtin::BI__builtin___memset_chk:
-  case Builtin::BI__builtin___strlcat_chk:
-  case Builtin::BI__builtin___strlcpy_chk:
+//  case Builtin::BI__builtin___strlcat_chk:
+//  case Builtin::BI__builtin___strlcpy_chk:
   case Builtin::BI__builtin___strncat_chk:
   case Builtin::BI__builtin___strncpy_chk:
   case Builtin::BI__builtin___stpncpy_chk:
@@ -3803,10 +3803,10 @@ bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
   switch (CMId) {
   case 0:
     return false;
-  case Builtin::BIstrlcpy: // fallthrough
+/*  case Builtin::BIstrlcpy: // fallthrough
   case Builtin::BIstrlcat:
     CheckStrlcpycatArguments(TheCall, FnInfo);
-    break;
+    break;*/
   case Builtin::BIstrncat:
     CheckStrncatArguments(TheCall, FnInfo);
     break;
index bea8f3f13ba2148c6369bdb7ba92ac63660817ef..208f23bf7582542f1f0c375e1997ab74bdbe6589 100644 (file)
@@ -741,9 +741,9 @@ void GenericTaintChecker::initTaintRules(CheckerContext &C) const {
        TR::Prop({{1, 2}}, {{0, ReturnValueIndex}})},
       {{CDM::CLibraryMaybeHardened, {"strncat"}},
        TR::Prop({{0, 1, 2}}, {{0, ReturnValueIndex}})},
-      {{CDM::CLibraryMaybeHardened, {"strlcpy"}}, TR::Prop({{1, 2}}, {{0}})},
+/*      {{CDM::CLibraryMaybeHardened, {"strlcpy"}}, TR::Prop({{1, 2}}, {{0}})},
       {{CDM::CLibraryMaybeHardened, {"strlcat"}}, TR::Prop({{0, 1, 2}}, {{0}})},
-
+*/
       // Usually the matching mode `CDM::CLibraryMaybeHardened` is sufficient
       // for unified handling of a function `FOO()` and its hardened variant
       // `__FOO_chk()`, but in the "sprintf" family the extra parameters of the
index b669ee68cdd9540a66bb1429120c838aa2ba53ec..63eed0156a75d7d919dab76a6249e322bac49d26 100644 (file)
@@ -195,12 +195,10 @@ void test18(void) {
   void *ptr;
 
   ptr = __builtin___memccpy_chk(dst, src, '\037', sizeof(src), sizeof(dst));
-  result = __builtin___strlcpy_chk(dst, src, sizeof(dst), sizeof(dst));
   result = __builtin___strlcat_chk(dst, src, sizeof(dst), sizeof(dst));
 
   ptr = __builtin___memccpy_chk(dst, src, '\037', sizeof(src));      // expected-error {{too few arguments to function call}}
   ptr = __builtin___strlcpy_chk(dst, src, sizeof(dst), sizeof(dst)); // expected-error {{incompatible integer to pointer conversion}}
-  ptr = __builtin___strlcat_chk(dst, src, sizeof(dst), sizeof(dst)); // expected-error {{incompatible integer to pointer conversion}}
 }
 
 void no_ms_builtins(void) {
@@ -214,7 +212,8 @@ void unavailable(void) {
   __builtin_operator_delete(0); // expected-error {{'__builtin_operator_delete' is only available in C++}}
 }
 
-size_t strlcpy(char * restrict dst, const char * restrict src, size_t size);
+/*
+  size_t strlcpy(char * restrict dst, const char * restrict src, size_t size);
 size_t strlcat(char * restrict dst, const char * restrict src, size_t size);
 
 void Test19(void)
@@ -235,6 +234,7 @@ void Test19(void)
                                                                                    // expected-note {{change size argument to be the size of the destination}} \
                                                                                   // expected-warning {{'strlcat' will always overflow; destination buffer has size 20, but size argument is 40}}
 }
+*/
 
 char * Test20(char *p, const char *in, unsigned n)
 {
diff --git a/clang/test/Sema/warn-strlcpycat-size.c b/clang/test/Sema/warn-strlcpycat-size.c
deleted file mode 100644 (file)
index c471665..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-// RUN: %clang_cc1 -Wstrlcpy-strlcat-size -verify -fsyntax-only %s
-
-typedef __SIZE_TYPE__ size_t;
-size_t strlcpy (char * restrict dst, const char * restrict src, size_t size);
-size_t strlcat (char * restrict dst, const char * restrict src, size_t size);
-size_t strlen (const char *s);
-
-char s1[100];
-char s2[200];
-char * s3;
-
-struct {
-  char f1[100];
-  char f2[100][3];
-} s4, **s5;
-
-int x;
-
-void f(void)
-{
-  strlcpy(s1, s2, sizeof(s1)); // no warning
-  strlcpy(s1, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-  strlcpy(s1, s3, strlen(s3)+1); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-  strlcat(s2, s3, sizeof(s3)); // expected-warning {{size argument in 'strlcat' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-  strlcpy(s4.f1, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-  strlcpy((*s5)->f2[x], s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-  strlcpy(s1+3, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}}
-}
-
-// Don't issue FIXIT for flexible arrays.
-struct S {
-  int y; 
-  char x[];
-};
-
-void flexible_arrays(struct S *s) {
-  char str[] = "hi";
-  strlcpy(s->x, str, sizeof(str));  // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}}
-}
-
-// Don't issue FIXIT for destinations of size 1.
-void size_1(void) {
-  char z[1];
-  char str[] = "hi";
-
-  strlcpy(z, str, sizeof(str));  // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}}
-}
-
-// Support VLAs.
-void vlas(int size) {
-  char z[size];
-  char str[] = "hi";
-
-  strlcpy(z, str, sizeof(str)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-}